<extend name="Public/base"/>
<block name="content">
    <table  id="teaTbl">
        <thead>
        <tr>
            <th><input  onclick="selectAll(this)" type="checkbox"></th>
            <th>编号</th>
            <th>姓名</th>
            <th>邮箱</th>
            <th>手机</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <volist name="teacher" id="v">
            <tr id="row_<{$v.teacher_id}>">
                <td><input class="slct" type="checkbox" value="<{$v.teacher_id}>"></td>
                <td><{$v.teacher_id}></td>
                <td><input name="tname" class="a" disabled type="text" value="<{$v.tname}>"></td>
                <td><input name="email" class="a" disabled type="text" value="<{$v.email}>"></td>
                <td><input name="mtel" class="a" disabled type="text" value="<{$v.mtel}>"></td>
                <td>
                    <button onclick="edit('row_<{$v.teacher_id}>')" class="button tiny edit">编辑</button>
                    <button onclick="save('<{$v.teacher_id}>')" style="display:none" class="button tiny save">保存</button>
                </td>
            </tr>
        </volist>
        </tbody>
    </table>
        <div>
            <span><{$page}></span>
        </div>
        <a class="button tiny" href="<{:U('addTeacher')}>">添加</a>
        <button onclick="unSelect()" class="button tiny">反选</button>
        <button onclick="delLot()" class="button tiny">删除(批量)</button>

<script>
    function edit(rowid) {
        $('#'+rowid+' .a').prop('disabled',false);
        $('#'+rowid+' .edit').hide();
        $('#'+rowid+' .save').show();
        //console.log('#'+id);exit;
    }
    function save(id) {
        $('#row_'+id+' .a').prop('disabled',true);
        $('#row_'+id+' .edit').show();
        $('#row_'+id+' .save').hide();

        var data = {
            teacher_id:id,
            tname:$('#row_'+id+' [name=tname]').val(),
            email:$('#row_'+id+' [name=email]').val(),
            mtel:$('#row_'+id+' [name=mtel]').val(),
        }

        $.post('<{:U("doEditTeacher")}>',data,function (data) {
            if(data.error!==0){
                alert(data.msg);
            }
        });

    }
    //全选
    function selectAll(obj) {
        $('#teaTbl tbody .slct').prop('checked',$(obj).prop('checked'));
    }
    //反选
    function unSelect() {
        $('#teaTbl tbody .slct').map(function(){
            $(this).prop('checked',!$(this).prop('checked'));
        });
    }

    //批量删除
    function delLot() {//you
        if(!confirm('确认批量删除吗')){
            return;
        }
        var ids = $('#teaTbl tbody .slct:checked').map(function () {
            $(this).parent().parent().remove();
            return $(this).val();
        });
        ids  = ids.get().join();
        $.post('<{:U("doDelTeacher")}>',{ids:ids},function (data) {
            alert(data.msg);
        });
    }

</script>
</block>